package com.hxkcloud.nurse.views;


import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.PopupWindow;

import com.hxkcloud.nurse.R;


public class MyBasePopuWindow extends PopupWindow {
    private View mMenuView;

    public View getmMenuView() {
        return mMenuView;
    }

    public MyBasePopuWindow(Activity context, OnClickListener itemsOnClick, int resourseId) {
        super(context);
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mMenuView = inflater.inflate(resourseId, null);

        // 设置SelectPicPopupWindow的View
        this.setContentView(mMenuView);
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(LayoutParams.MATCH_PARENT);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(LayoutParams.MATCH_PARENT); // WRAP_CONTENT
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        // 设置SelectPicPopupWindow弹出窗体动画效果
        //this.setAnimationStyle(R.style.AnimBottom);

        // 设置SelectPicPopupWindow淡入窗体动画效果
        this.setAnimationStyle(R.style.popupwindow_anim_alpha);
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0x7d7f7f7f); // 0x7d7f7f7f
        // 设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
        // mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
        mMenuView.setOnTouchListener(new OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {

                int height = mMenuView.findViewById(R.id.line_content).getTop();
                int bottom = mMenuView.findViewById(R.id.line_content).getBottom();
                int y = (int) event.getY();
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (y < height || bottom < y) {
                        //Log.d("xxxx", "xxxxx");
                        dismiss();
                        //return false;
                    }
                }

                return true;
            }
        });
    }


}
